package com.miwzn.boot.modules.sys.web;

import com.miwzn.base.AbstractController;
import com.miwzn.boot.modules.sys.entity.po.SysUser;
import com.miwzn.boot.modules.sys.entity.qm.SysUserQuery;
import com.miwzn.boot.modules.sys.entity.dto.SysUserDto;
import com.miwzn.boot.modules.sys.service.SysUserService;
import com.miwzn.comm.ResponseEntity;
import com.miwzn.comm.annotation.OperationLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: wzn
 * @Date: 2018-12-07 16:27:28
 * @Description: www.miwzn.com mvc api
 */
@ResponseBody
@Controller
@RequestMapping("sys/user")
public class SysUserController extends AbstractController<SysUser, SysUserDto, SysUserQuery> {
    private static Logger logger = LoggerFactory.getLogger(SysUserController.class);

    @Autowired
    private SysUserService sysUserService;

    /**
     * 根据ID获取信息
     *
     * @param id
     *
     * @return
     */
    @OperationLog(operation = "用户",content ="根据ID查询用户")
    @RequiresUser
    @GetMapping("/getById/{id}")
    public ResponseEntity getById(@PathVariable("id") String id) {
        return super.getById(id);
    }

    /**
     * 列表
     *
     * @param entity
     *
     * @return
     */
    @OperationLog(operation = "用户",content ="查询用户列表")
    @RequiresPermissions("sys:user:list")
    @GetMapping("/list")
    public ResponseEntity list(SysUserQuery entity) {
        return super.listD(entity);
    }

    /**
     * 添加
     *
     * @param entity
     *
     * @return
     */
    @OperationLog(operation = "用户",content ="添加用户")
    @RequiresPermissions("sys:user:add")
    @PostMapping("add")
    public ResponseEntity add(@RequestBody SysUserDto entity) {
        return super.add(entity);
    }

    /**
     * 更新
     *
     * @param entity
     *
     * @return
     */
    @OperationLog(operation = "用户",content ="更新用户")
    @RequiresPermissions("sys:user:update")
    @PutMapping("update")
    public ResponseEntity update(@RequestBody SysUserDto entity) {
        SysUser sysUser = sysUserService.selectByPrimaryKey(entity.getId());
        sysUser.setSex(entity.getSex());
        sysUser.setUsername(entity.getUsername());
        sysUser.setMobile(entity.getMobile());
        sysUser.setPicUrl(entity.getPicUrl());
        sysUser.setBirthday(entity.getBirthday());
        sysUser.setEmail(entity.getEmail());
        sysUser.setDeptId(entity.getDeptId());
        sysUser.setLocked(entity.getLocked());
        return super.update(sysUser);
    }

    /**
     * 软删除
     *
     * @param id
     *
     * @return
     */
    @OperationLog(operation = "用户",content ="删除用户")
    @RequiresPermissions("sys:user:delFlag")
    @DeleteMapping("/delFlag/{id}")
    public ResponseEntity deleteFlag(@PathVariable("id") String id) {
        return super.deleteFlag(id);
    }

    /**
     * 软删除
     *
     * @param ids
     *
     * @return
     */
    @OperationLog(operation = "用户",content ="删除用户")
    @RequiresPermissions("sys:user:delFlag")
    @DeleteMapping("/delFlag")
    public ResponseEntity deleteFlag(@RequestBody String[] ids) {
        return super.deleteFlag(ids);
    }

    /**
     * 硬删除
     *
     * @param id
     *
     * @return
     */
    @OperationLog(operation = "用户",content ="删除用户")
    @RequiresPermissions("sys:user:del")
    @DeleteMapping("/del/{id}")
    public ResponseEntity delete(@PathVariable("id") String id) {
        return super.delete(id);
    }

    /**
     * 硬删除
     *
     * @param ids
     *
     * @return
     */
    @OperationLog(operation = "用户",content ="删除用户")
    @RequiresPermissions("sys:user:del")
    @DeleteMapping("/del")
    public ResponseEntity delete(@RequestBody String[] ids) {
        return super.delete(ids);
    }

}
